package com.aiiter.web.controller.house;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.aiiter.house.domain.HouseContract;
import com.aiiter.house.service.IHouseContractService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.aiiter.common.annotation.Log;
import com.aiiter.common.core.controller.BaseController;
import com.aiiter.common.core.domain.AjaxResult;
import com.aiiter.common.enums.BusinessType;
import com.aiiter.common.utils.poi.ExcelUtil;
import com.aiiter.common.core.page.TableDataInfo;

/**
 * 房间合同Controller
 *
 * @author ruoyi
 * @date 2024-09-22
 */
@RestController
@RequestMapping("/house/contract")
public class HouseContractController extends BaseController
{
    @Autowired
    private IHouseContractService houseContractService;

    /**
     * 查询房间合同列表
     */
    @PreAuthorize("@ss.hasPermi('system:contract:list')")
    @GetMapping("/list")
    public TableDataInfo list(HouseContract houseContract)
    {
        startPage();
        List<HouseContract> list = houseContractService.selectHouseContractList(houseContract);
        return getDataTable(list);
    }

    /**
     * 导出房间合同列表
     */
    @PreAuthorize("@ss.hasPermi('system:contract:export')")
    @Log(title = "房间合同", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseContract houseContract)
    {
        List<HouseContract> list = houseContractService.selectHouseContractList(houseContract);
        ExcelUtil<HouseContract> util = new ExcelUtil<HouseContract>(HouseContract.class);
        util.exportExcel(response, list, "房间合同数据");
    }

    /**
     * 获取房间合同详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:contract:query')")
    @GetMapping(value = "/{contractId}")
    public AjaxResult getInfo(@PathVariable("contractId") Long contractId)
    {
        return success(houseContractService.selectHouseContractByContractId(contractId));
    }

    /**
     * 新增房间合同
     */
    @PreAuthorize("@ss.hasPermi('system:contract:add')")
    @Log(title = "房间合同", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HouseContract houseContract)
    {
        return toAjax(houseContractService.insertHouseContract(houseContract));
    }

    /**
     * 修改房间合同
     */
    @PreAuthorize("@ss.hasPermi('system:contract:edit')")
    @Log(title = "房间合同", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HouseContract houseContract)
    {
        return toAjax(houseContractService.updateHouseContract(houseContract));
    }

    /**
     * 删除房间合同
     */
    @PreAuthorize("@ss.hasPermi('system:contract:remove')")
    @Log(title = "房间合同", businessType = BusinessType.DELETE)
    @DeleteMapping("/{contractIds}")
    public AjaxResult remove(@PathVariable Long[] contractIds)
    {
        return toAjax(houseContractService.deleteHouseContractByContractIds(contractIds));
    }
}
